<form class="layui-form" action="{:url('',['id'=>$id])}" method="post" id="editForm" lay-filter="edit-form">
    {:FormExt::input('入库数量', 'stock', $stock, '入库数量', '', 'lay-verify="number"')}
    {:FormExt::showText('单位', $unit)}
    <div class="pop-bottom-bar">
    	<input type="hidden" class="field-id" name="id">
        <button type="submit" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="formSubmit" hisi-data="{pop: true, refresh: true, callback: callbackUpdateStock}">提交保存</button>
        <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
    </div>
</form>

{include file="system@block/layui" /}
    
<script>
layui.use(['tool', 'form', 'layer'], function() {
	var $ = layui.jquery;
	var form = layui.form;
	var layer = layui.layer;
	
	$('input[name=stock]').focus();
	
	window.calAmount = function(){
		var d = form.val("edit-form");
		var stock = 0;
		var unitPrice = 0;
		var reg = /((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/;
		
		if (d.stock != '') {
			if (!reg.test(d.stock)) {
				layer.msg('数量格式错误', {icon: 2,anim: 6});
				return false;
			}
			stock = layui.tool.parseFloat(d.stock, 2);
		}
		
		$('input[name=amount]').val(layui.tool.bcmul(stock, unitPrice));
	};
	
	$(document).on('blur','input[name=stock],input[name=unit_price]',function(){
		calAmount();
	});
    window.callbackUpdateStock = function(obj, res) {
		if (res.code == 1) layer.msg(res.msg, {icon: 1,end:function(){parent.layui.layer.closeAll();parent.layui.table.reload('dataTable');}});
	}
});
</script>